package com.wenhai.leetcode.array;

/**
 *https://leetcode-cn.com/problems/squares-of-a-sorted-array/
 *
 * @author wenhai
 * @date   2021/4/1
 */
public class _977有序数组的平方 {

    public int[] sortedSquares(int[] nums) {
        int[] result = new int[nums.length];
        for (int i = 0, j = nums.length - 1, r = nums.length - 1; i <= j;r-- ) {

            if (nums[i] * nums[i] > nums[j] * nums[j]) {
                result[r] = nums[i] * nums[i];
                i++;
            } else {
                result[r] = nums[j] * nums[j];
                j--;
            }
        }
        return result;
    }
}
